﻿using GraduationProject.Model;
using GraduationProject.Webs.Areas.Admin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GraduationProject.Webs.Controllers
{
    /// <summary>
    /// 文章种类控制器
    /// </summary>
    public class SortController : Controller
    {
        #region 字段
        public readonly GraduationProject.RDBMS.SortList _sortService = new RDBMS.SortList();
        #endregion

        // GET: Sort
        public ActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 获取下拉框城市列表
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SelectCiteList(int[] ProvinceIDs)
        {
            Province[] Sort;
            int TotalCount = 0;
            using (var conn = new RDBMS.SortList())
            {
                if (conn.TryGetCiteList(out Sort, ProvinceIDs: ProvinceIDs))
                {
                    return new NewtonsoftJson(new { code = 0, msg = "成功", count = TotalCount, data = Sort });
                }
            }
            return Json(new { code = 1, msg = "抱歉,暂无数据", count = 0, data = new List<Province>() });
        }
        /// <summary>
        ///获取下拉框景区列表
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SelectLevelList()
        {
            ScenicLevel[] Sort;
            int TotalCount = 0;
            using (var conn = new RDBMS.SortList())
            {
                if (conn.TryGetScenicLevelList(out Sort,null))
                {
                    return new NewtonsoftJson(new { code = 0, msg = "成功", count = TotalCount, data = Sort });
                }
            }
            return Json(new { code = 1, msg = "抱歉,暂无数据", count = 0, data = new List<ScenicLevel>() });
        }
        /// <summary>
        /// 地图页搜索框搜索
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult TryGetSortListBySearch(decimal XPlace, decimal YPlace,string SearchText)
        {
            SortList[] Sort;
            int TotalCount = 0;
            using (var conn = new RDBMS.SortList())
            {
                if (conn.TryGetSortListBySearch(out Sort, out XPlace, out YPlace, SearchText))
                {
                    return new NewtonsoftJson(new { code = 0, msg = "成功", count = TotalCount, data = Sort });
                }
            }
            return Json(new { code = 1, msg = "抱歉,暂无数据", count = 0, data = new List<SortList>() });
        }
    }
}